﻿<%@ WebHandler Language="C#" Class="ShowListLitigation" %>

using System;
using System.Web;
using System.Text;
using System.Data;
using Chenxin.Lib.Utility;
using Chenxin.Lib.Business;
using Chenxin.Lib.Business.BLL;

public class ShowListLitigation : AjaxHandlerBase
{
    /// <summary>
    /// 基本权限项
    /// </summary>
    public ShowListLitigation()
    {
        //诉讼申请
        htTypePermit.Add("applylitigation", Constants.Permit_ApplyLitigation);
        //诉讼审批
        htTypePermit.Add("auditinglitigation", Constants.Permit_AuditingLitigation);
        //立案审理
        htTypePermit.Add("cognizancelitigation", Constants.Permit_CognizanceLitigation);
        //裁决执行
        htTypePermit.Add("verdictlitigation", Constants.Permit_VerdictLitigation);
        //结案
        htTypePermit.Add("closecaselitigation", Constants.Permit_ClosecaseLitigation);
        //详情查看
        htTypePermit.Add("showdetiallitigation", Constants.Permit_ShowDetialLitigation);
        //上传附件
        htTypePermit.Add("lituploadattach", Constants.Permit_LitUpLoadAttach);
        //导出
        htTypePermit.Add("export", Constants.Permit_Litigation_Export);  
    }
    
    //可上传附件类型
    public static string[] FileExt = new string[] { ".xls", 
                                                    ".doc", 
                                                    ".pdf", 
                                                    ".rar", 
                                                    ".zip", 
                                                    ".jpg", 
                                                    ".xlsx", 
                                                    ".docx" };
    
    override public void RequestProcess(HttpContext context)
    {
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        string strOp = context.Request["op"];
        string strResponse = "";
        switch (strOp.ToLower())
        {
            //获取实体
            case "getmodel":
                strResponse = GetModel(context);
                break;
            //获取实体
            case "getsubmodel":
                strResponse = GetSubModel(context);
                break;
            //获取实体
            case "getaudmodel":
                strResponse = GetAudModel(context);
                break;
            //获取实体
            case "getdepart":
                strResponse = GetDepart(context);
                break;
            //查询
            case "search":
                strResponse = Search(context);
                break;
            //诉讼申请
            case "applylitigation":
                strResponse = Apply(context);
                break;
            //诉讼审批
            case "auditinglitigation":
                strResponse = Auditing(context);
                break;
            //立案审理
            case "cognizancelitigation":
                strResponse = Cognizance(context);
                break;
            //裁决执行
            case "verdictlitigation":
                strResponse = Verdict(context);
                break;
            //结案
            case "closecaselitigation":
                strResponse = CloseCase(context);
                break;
            //上传附件
            case "uploadattach":
                strResponse = FileUpload(context);
                break;
            default:
                break;
        }
        context.Response.Write(strResponse);
    }

    /// <summary>
    /// 获取实体
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string GetModel(HttpContext context)
    {
        try
        {
            Chenxin.Lib.Business.Entity.t_Business_LitigationInfo model = null;

            model = Chenxin.Lib.Business.DAL.t_Business_LitigationInfo.GetModel(new Guid(context.Request["modelid"]));

            if (model != null)
            {
                return retExecResult(Constants.ExecResult.Succ, "", model);
            }
            else
            {
                return retExecResult(Constants.ExecResult.Error, "数据不存在，获取信息失败！", "");
            }
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }

    /// <summary>
    /// 获取实体
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string GetSubModel(HttpContext context)
    {
        try
        {
            StringBuilder sb = new StringBuilder();
            
            Chenxin.Lib.Business.Entity.t_Business_LitigationInfo model = null;
            model = Chenxin.Lib.Business.DAL.t_Business_LitigationInfo.GetModel(new Guid(context.Request["modelid"]));

            Chenxin.Lib.Business.Entity.t_Business_LitigationSubInfo modelSub = null;
            Chenxin.Lib.Business.BLL.LitigationSub bllLitigationSub = new Chenxin.Lib.Business.BLL.LitigationSub();
            modelSub = bllLitigationSub.GetModel(new Guid(context.Request["modelid"]));

            if (modelSub != null)
            {
                sb.AppendFormat("litigationInfo:{0},litigationSubInfo:{1}", JsonHelp.Convert2Json(model), JsonHelp.Convert2Json(modelSub));
            }
            else
            {
                sb.AppendFormat("litigationInfo:{0}", JsonHelp.Convert2Json(model));
            }
            
            return string.Format("{{success:1,msg:'',data:{{{0}}}}}", sb.ToString());
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }

    /// <summary>
    /// 获取实体
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string GetAudModel(HttpContext context)
    {
        try
        {
            Chenxin.Lib.Business.Entity.t_Business_LitigationInfo model = null;

            model = Chenxin.Lib.Business.DAL.t_Business_LitigationInfo.GetModel(new Guid(context.Request["modelid"]));

            if (model != null)
            {
                model.ApproveDepartId = CurrentUserInfo.DepartId;
                model.ApproveDepart = CurrentUserInfo.DepartName;
                model.ApproveEmployeeId = CurrentUserInfo.UserId;
                model.ApproveEmployee = CurrentUserInfo.UserName;
                return retExecResult(Constants.ExecResult.Succ, "", model);
            }
            else
            {
                return retExecResult(Constants.ExecResult.Error, "数据不存在，获取信息失败！", "");
            }
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }

    /// <summary>
    /// 获取实体
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string GetDepart(HttpContext context)
    {
        try
        {
            Chenxin.Lib.Business.Entity.t_Business_LitigationInfo model = new Chenxin.Lib.Business.Entity.t_Business_LitigationInfo();
            model.AppDepartId = CurrentUserInfo.DepartId;
            model.AppDepart = CurrentUserInfo.DepartName;
            return retExecResult(Constants.ExecResult.Succ, "", model);
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }
    
    //*******************************************
    //功能概要       ：获得诉讼一览
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：获得诉讼一览
    //作成者         ：zou.xiaochun
    //作成日         ：2010-09-28
    //*******************************************
    private string Search(HttpContext context)
    {
        try
        {
            //页码
            int strPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;
            //页显示行数
            int strPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 30 : int.Parse(context.Request["pagesize"]);
            //查询条件
            string sqlWhere = GenerateCondition(context);

            //查询分页信息
            Chenxin.Lib.Business.BLL.LitigationBase bllLit = new Chenxin.Lib.Business.BLL.LitigationBase();
            System.Data.DataSet ds = bllLit.GetModelListByCoditions(sqlWhere, strPageIndex, strPageSize);
            //总页数
            int count = (int)ds.Tables[1].Rows[0][0];

            return string.Format("{{success:'1',msg:'{0}',data:{{count:'{1}',{2}}}}}", Resources.Message.Global_Msg_SUCCESS, count, JsonHelp.Convert2Json(ds.Tables[0]));
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }

    //*******************************************
    //功能概要       ：查询权限
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理信息提示
    //功能詳細       ：生成查询条件语句
    //作成者         ：chen.yugong
    //作成日         ：2010-06-29
    //修改者         ：王玮
    //修改日         ：2010-07-13
    //*******************************************
    public string GenerateCondition(HttpContext context)
    {
        try
        {
            //获取页面查询条件
            Guid city = (string.IsNullOrEmpty(context.Request["cityid"])) ? Guid.Empty : new Guid(context.Request["cityid"]);
            Guid company = (string.IsNullOrEmpty(context.Request["companyid"])) ? Guid.Empty : new Guid(context.Request["companyid"]);
            Guid businessdistrict = (string.IsNullOrEmpty(context.Request["areaid"])) ? Guid.Empty : new Guid(context.Request["areaid"]);
            Guid departs = (string.IsNullOrEmpty(context.Request["departid"])) ? Guid.Empty : new Guid(context.Request["departid"]);
            Guid employee = (string.IsNullOrEmpty(context.Request["userid"])) ? Guid.Empty : new Guid(context.Request["userid"]);

            string starttime = context.Request.QueryString["DateFr"];
            string endtime = context.Request.QueryString["DateTo"];
            string keyword = context.Request.QueryString["HouseAddress"];
            string status = context.Request.QueryString["Status"];
            
            System.Text.StringBuilder sb = new System.Text.StringBuilder();

            //判断级联菜单
            if (employee != Guid.Empty)
                sb.AppendFormat(" and (AddEmployeeId = '{0}') ", employee);
            else if (departs != Guid.Empty)
                sb.AppendFormat(" and (AppDepartId = '{0}')", departs);
            else if (businessdistrict != Guid.Empty)
            {
                Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo item = null;
                string strCachkey = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_DEPARTMENT, businessdistrict);
                Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
                item = cs.GetObject<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo>(strCachkey);
                if (!cs.Hit)
                {
                    item = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetModel(businessdistrict);
                    if (item != null) cs.Set(strCachkey, item, DateTime.Now.AddDays(1));
                }

                if (item == null) return string.Format("{{success:'0',msg:'{0}',data:''}}", Resources.Message.Global_Err_GetBusDis);

                sb.AppendFormat(" and (AppDepartId in (select departId from v_Hr_DepartmentInfo where DepartSrc like '{0}%'))", item.DepartSrc);
            }
            else if (company != Guid.Empty)
            {
                sb.AppendFormat(" and AppCompanyId = '{0}'", company);
            }
            else if (city != Guid.Empty)
            {
                sb.AppendFormat(" and AppCityId = '{0}'", city);
            }
            else
            {
                sb.AppendFormat(" and AppCompanyId = '{0}'", CurrentUserInfo.CompanyId);
            }

            //查询权限判断权限
            System.Text.StringBuilder sb1 = new System.Text.StringBuilder();
            if (CurrentUserInfo.ContainsPermit(Constants.Permit_LitigationSearch_All))
            {
                sb1.Append(" (1=1) ");
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_LitigationSearch_City))
            {
                sb1.AppendFormat(" (AppCityId = '{0}')", CurrentUserInfo.CityId);
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_LitigationSearch_Company))
            {
                sb1.AppendFormat(" (AppCompanyId = '{0}')", CurrentUserInfo.CompanyId);
            }
            else if (CurrentUserInfo.ContainsPermit(Constants.Permit_LitigationSearch_Depart))
            {
                sb1.Append(" (EXISTS(");
                sb1.AppendFormat("Select 1 from t_Business_EmpSetting M WHERE t_Business_LitigationInfo.AppDepartId=M.DepartId And M.Userid= '{0}' and SearchLitigation=1", CurrentUserInfo.UserId.ToString());
                sb1.Append(")) ");
            }
            else
            {
                sb1.AppendFormat(" (AddEmployeeId = '{0}')", CurrentUserInfo.UserId);
            }

            if (!String.IsNullOrEmpty(sb.ToString()))
                sb1.Append(sb.ToString());

            if (!String.IsNullOrEmpty(starttime))
            {
                sb1.Append(string.Format(" and convert(varchar(10),(convert(datetime,AppDate,120)),120)  >= '{0}'", (starttime)));
            }
            if (!String.IsNullOrEmpty(endtime))
            {
                sb1.Append(string.Format(" and convert(varchar(10),(convert(datetime,AppDate,120)),120)  <= '{0}'", (endtime)));
            }
            if (!String.IsNullOrEmpty(keyword))
            {
                sb1.AppendFormat(" And HouseAddress LIKE '%{0}%'", keyword);
            }
            if (!String.IsNullOrEmpty(status))
            {
                switch (status)
                {
                    case "0":
                        sb1.Append(" And Status = '0'");
                        break;
                    case "-10":
                        sb1.Append(" And Status = '-10'");
                        break;
                    case "10":
                        sb1.Append(" And Status = '10'");
                        break;
                    case "20":
                        sb1.Append(" And Status = '20'");
                        break;
                    case "30":
                        sb1.Append(" And Status = '30'");
                        break;
                    case "40":
                        sb1.Append(" And Status = '40'");
                        break;
                }
            }
            return sb1.ToString();
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}：{1}',data:''}}", Resources.Message.Global_Err_Exception, ex.Message);
        }
    }

    //*******************************************
    //功能概要       ：诉讼申请
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：诉讼申请
    //作成者         ：zou.xiaochun
    //作成日         ：2010-09-28
    //*******************************************
    private string Apply(HttpContext context)
    {
        //诉讼申请信息
        string litigation = context.Request.Params["model"];

        //诉讼信息业务类
        Chenxin.Lib.Business.BLL.LitigationBase bllLitigation = new Chenxin.Lib.Business.BLL.LitigationBase();

        //诉讼信息
        Chenxin.Lib.Business.Entity.t_Business_LitigationInfo entLitigation =
            (Chenxin.Lib.Business.Entity.t_Business_LitigationInfo)JsonHelp.Convert2Entity(litigation,
                    typeof(Chenxin.Lib.Business.Entity.t_Business_LitigationInfo));

        entLitigation = CompleteLitigation(entLitigation, "诉讼申请");

        //诉讼信息录入
        bllLitigation.Add(entLitigation);

        string text = string.Empty;
        text = CurrentUserInfo.UserName + "：诉讼申请。成交编号：" + entLitigation.ContractCode;
        AddLog(text, BusinessType.BusinessTypeComboList()["OprType_ApplyLitigation"].ToString());
        
        return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_ApplyLitigation_Succ, "");
    }

    //*******************************************
    //功能概要       ：诉讼审批
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：诉讼审批
    //作成者         ：zou.xiaochun
    //作成日         ：2010-09-28
    //*******************************************
    private string Auditing(HttpContext context)
    {
        //诉讼信息
        string litigation = context.Request.Params["model"];

        //诉讼信息
        Chenxin.Lib.Business.BLL.LitigationBase bllLitigation = new Chenxin.Lib.Business.BLL.LitigationBase();

        //诉讼信息
        Chenxin.Lib.Business.Entity.t_Business_LitigationInfo entLitigation =
            (Chenxin.Lib.Business.Entity.t_Business_LitigationInfo)JsonHelp.Convert2Entity(litigation,
                    typeof(Chenxin.Lib.Business.Entity.t_Business_LitigationInfo));

        entLitigation = CompleteLitigation(entLitigation, "诉讼审批");

        //①诉讼信息
        bllLitigation.Update(entLitigation);
        if (entLitigation.Status == 10)
        {
            Chenxin.Lib.Business.DAL.t_Contract_BaseInfo.ChangeStatus(entLitigation.ContractCode, 20);
        }
        string text = string.Empty;
        text = CurrentUserInfo.UserName + "：诉讼审批。成交编号：" + entLitigation.ContractCode;
        AddLog(text, BusinessType.BusinessTypeComboList()["OprType_AuditingLitigation"].ToString());
        return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_AuditingLitigation_Succ, "");
    }

    //*******************************************
    //功能概要       ：诉讼审理
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：诉讼审理
    //作成者         ：zou.xiaochun
    //作成日         ：2010-09-28
    //*******************************************
    private string Cognizance(HttpContext context)
    {
        //诉讼信息
        string[] strModel = context.Request.Params["model"].ToString().Split(',');
        string litigation = string.Empty;
        string litigationsub = string.Empty;
        
        if (strModel[1].Substring(0, 8) == "RecordId")
        {
            litigation = strModel[0] + "," + strModel[1] + "}";
            litigationsub = "{" + strModel[2] + "," + strModel[3] + "," + strModel[4] + "," + strModel[5];
        }
        else if (strModel[3].Substring(0, 8) == "RecordId")
        {
            litigation = strModel[0] + "," + strModel[3] + "}";
            litigationsub = "{" + strModel[1] + "," + strModel[2] + "," + strModel[4] + "," + strModel[5];
        }
        else if (strModel[5].Substring(0, 8) == "RecordId")
        {
            litigation = strModel[0] + "," + strModel[5];
            litigationsub = "{" + strModel[1] + "," + strModel[2] + "," + strModel[3] + "," + strModel[4] + "}";
        }
        
        //诉讼信息
        Chenxin.Lib.Business.BLL.LitigationSub bllLitigationSub = new Chenxin.Lib.Business.BLL.LitigationSub();
        Chenxin.Lib.Business.BLL.LitigationBase bllLitigation = new Chenxin.Lib.Business.BLL.LitigationBase();
        
        //诉讼信息
        Chenxin.Lib.Business.Entity.t_Business_LitigationInfo entLitigation =
            (Chenxin.Lib.Business.Entity.t_Business_LitigationInfo)JsonHelp.Convert2Entity(litigation,
                    typeof(Chenxin.Lib.Business.Entity.t_Business_LitigationInfo));

        //诉讼信息
        Chenxin.Lib.Business.Entity.t_Business_LitigationSubInfo entLitigationSub =
            (Chenxin.Lib.Business.Entity.t_Business_LitigationSubInfo)JsonHelp.Convert2Entity(litigationsub,
                    typeof(Chenxin.Lib.Business.Entity.t_Business_LitigationSubInfo));

        entLitigation = CompleteLitigation(entLitigation, "诉讼审理");
        
        entLitigationSub.MainId = entLitigation.RecordId;
        Chenxin.Lib.Business.Entity.t_Business_LitigationSubInfo entOldLitigationSub = bllLitigationSub.GetModel(entLitigationSub.MainId);
        if (entOldLitigationSub == null)
        {
            entLitigationSub.RecordId = Guid.NewGuid();
            entLitigationSub.MainId = entLitigation.RecordId;
            bllLitigationSub.Add(entLitigationSub);
        }
        else
        {
            int tempStatus = int.Parse(entLitigation.CurrentTrialStatus.ToString());
            entLitigationSub = CompleteLitigationSub(tempStatus, entLitigationSub,entOldLitigationSub);
            bllLitigationSub.Update(entLitigationSub);
        }
        
        //①诉讼信息录入
        bllLitigation.Update(entLitigation);
        string text = string.Empty;
        text = CurrentUserInfo.UserName + "：诉讼审理。成交编号：" + entLitigation.ContractCode;
        AddLog(text, BusinessType.BusinessTypeComboList()["OprType_CognizanceLitigation"].ToString());
        return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_CognizanceLitigation_Succ, "");
    }

    //*******************************************
    //功能概要       ：裁决执行
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：裁决执行
    //作成者         ：zou.xiaochun
    //作成日         ：2010-09-28
    //*******************************************
    private string Verdict(HttpContext context)
    {
        //诉讼信息
        string litigation = context.Request.Params["model"];

        //诉讼信息
        Chenxin.Lib.Business.BLL.LitigationBase bllLitigation = new Chenxin.Lib.Business.BLL.LitigationBase();

        //诉讼信息
        Chenxin.Lib.Business.Entity.t_Business_LitigationInfo entLitigation =
            (Chenxin.Lib.Business.Entity.t_Business_LitigationInfo)JsonHelp.Convert2Entity(litigation,
                    typeof(Chenxin.Lib.Business.Entity.t_Business_LitigationInfo));

        entLitigation = CompleteLitigation(entLitigation, "诉讼裁决");

        //诉讼信息录入
        bllLitigation.Update(entLitigation);
        string text = string.Empty;
        text = CurrentUserInfo.UserName + "：裁决执行。成交编号：" + entLitigation.ContractCode;
        AddLog(text, BusinessType.BusinessTypeComboList()["OprType_VerdictLitigation"].ToString());
        return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_VerdictLitigation_Succ, "");
    }

    //*******************************************
    //功能概要       ：结案
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：结案
    //作成者         ：zou.xiaochun
    //作成日         ：2010-09-28
    //*******************************************
    private string CloseCase(HttpContext context)
    {
        //诉讼信息
        string litigation = context.Request.Params["model"];

        //诉讼信息
        Chenxin.Lib.Business.BLL.LitigationBase bllLitigation = new Chenxin.Lib.Business.BLL.LitigationBase();

        //诉讼信息
        Chenxin.Lib.Business.Entity.t_Business_LitigationInfo entLitigation =
            (Chenxin.Lib.Business.Entity.t_Business_LitigationInfo)JsonHelp.Convert2Entity(litigation,
                    typeof(Chenxin.Lib.Business.Entity.t_Business_LitigationInfo));

        entLitigation = CompleteLitigation(entLitigation, "诉讼结案");

        //诉讼信息录入
        bllLitigation.Update(entLitigation);
        string text = string.Empty;
        text = CurrentUserInfo.UserName + "：诉讼结案。成交编号：" + entLitigation.ContractCode;
        AddLog(text, BusinessType.BusinessTypeComboList()["OprType_CloseCaseLitigation"].ToString());
        return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_CloseCaseLitigation_Succ, "");
    }

    /// <summary>
    /// 上传附件
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string FileUpload(HttpContext context)
    {
        try
        {
            string recordId = context.Request.Params["recordId"];
            HttpPostedFile file = context.Request.Files["FileData"];
            string strFileName = file.FileName.ToString();
            string strFileExt = strFileName.Substring(strFileName.LastIndexOf('.'));

            bool inExt = false;
            for (int i = 0; i < FileExt.Length; i++)
            {
                if (strFileExt.Equals(FileExt[i].ToString()))
                {
                    inExt = true;
                }
            }

            if (!inExt)
            {
                return retExecResult(Constants.ExecResult.Error, "" + strFileExt + "文件格式不允许上传！", "");
            }
            else
            {
                Upload(context, Constants.FilePath_Litigation, recordId);
                return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_LitigationUpLoad_Succ, "");
            }
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }
    
    //*******************************************
    //功能概要       ：填充诉讼信息字段
    //参数説明       ：context 请求上下文
    //返回值説明     ：诉讼信息实体
    //功能詳細       ：填充诉讼信息字段
    //作成者         ：zou.xiaochun
    //作成日         ：2010-09-28
    //*******************************************
    private Chenxin.Lib.Business.Entity.t_Business_LitigationInfo CompleteLitigation(Chenxin.Lib.Business.Entity.t_Business_LitigationInfo entLitigation, string status)
    {
        try
        {
            //诉讼信息处理业务类
            Chenxin.Lib.Business.BLL.LitigationBase bllLitigation = new Chenxin.Lib.Business.BLL.LitigationBase();
            Chenxin.Lib.Business.Entity.t_Business_LitigationInfo entOldLitigation = bllLitigation.GetModel(entLitigation.RecordId);

            if (status.Equals("诉讼申请"))
            {
                entLitigation.RecordId = Guid.NewGuid();
                entLitigation.AppCityId = CurrentUserInfo.CityId;
                entLitigation.AppCity = CurrentUserInfo.CityName;
                entLitigation.AppCompanyId = CurrentUserInfo.CompanyId;
                entLitigation.AppCompany = CurrentUserInfo.CompanyName;
                entLitigation.AddTime = DateTime.Now;
                entLitigation.AddEmployeeId = CurrentUserInfo.UserId;
                entLitigation.AddEmployee = CurrentUserInfo.UserName;
                entLitigation.AddDepartId = CurrentUserInfo.DepartId;
                entLitigation.AddDepart = CurrentUserInfo.DepartName;
                entLitigation.Status = 0;
            }
            else if (status.Equals("诉讼审批"))
            {
                entLitigation.RecordId = entOldLitigation.RecordId;
                entLitigation.ContractId = entOldLitigation.ContractId;
                entLitigation.ContractCode = entOldLitigation.ContractCode;
                entLitigation.HouseAddress = entOldLitigation.HouseAddress;
                entLitigation.AppCityId = entOldLitigation.AppCityId;
                entLitigation.AppCity = entOldLitigation.AppCity;
                entLitigation.AppCompanyId = entOldLitigation.AppCompanyId;
                entLitigation.AppCompany = entOldLitigation.AppCompany;
                entLitigation.AppDepartId = entOldLitigation.AppDepartId;
                entLitigation.AppDepart = entOldLitigation.AppDepart;
                entLitigation.AppDate = entOldLitigation.AppDate;
                entLitigation.LitigationMoney = entOldLitigation.LitigationMoney;
                entLitigation.LitigationPerson = entOldLitigation.LitigationPerson;
                entLitigation.AddTime = entOldLitigation.AddTime;
                entLitigation.AddEmployeeId = entOldLitigation.AddEmployeeId;
                entLitigation.AddEmployee = entOldLitigation.AddEmployee;
                entLitigation.AddDepartId = entOldLitigation.AddDepartId;
                entLitigation.AddDepart = entOldLitigation.AddDepart;
                if (string.IsNullOrEmpty(entLitigation.ApproveEmployee) && string.IsNullOrEmpty(entLitigation.ApproveReason) && string.IsNullOrEmpty(entLitigation.Suggestion))
                {
                    entLitigation.Status = 10;
                }
                else
                {
                    if (string.IsNullOrEmpty(entLitigation.ApproveEmployee))
                    {
                        entLitigation.ApproveEmployeeId = CurrentUserInfo.UserId;
                        entLitigation.ApproveEmployee = CurrentUserInfo.UserName;
                    }
                    entLitigation.Status = -10;
                }
                entLitigation.ApproveOprEmpId = CurrentUserInfo.UserId;
                entLitigation.ApproveOprEmp = CurrentUserInfo.UserName;
                entLitigation.ApproveOprTime = DateTime.Now;
            }
            else if (status.Equals("诉讼审理"))
            {
                entLitigation.RecordId = entOldLitigation.RecordId;
                entLitigation.ContractId = entOldLitigation.ContractId;
                entLitigation.ContractCode = entOldLitigation.ContractCode;
                entLitigation.HouseAddress = entOldLitigation.HouseAddress;
                entLitigation.AppCityId = entOldLitigation.AppCityId;
                entLitigation.AppCity = entOldLitigation.AppCity;
                entLitigation.AppCompanyId = entOldLitigation.AppCompanyId;
                entLitigation.AppCompany = entOldLitigation.AppCompany;
                entLitigation.AppDepartId = entOldLitigation.AppDepartId;
                entLitigation.AppDepart = entOldLitigation.AppDepart;
                entLitigation.AppDate = entOldLitigation.AppDate;
                entLitigation.LitigationMoney = entOldLitigation.LitigationMoney;
                entLitigation.LitigationPerson = entOldLitigation.LitigationPerson;
                entLitigation.AddTime = entOldLitigation.AddTime;
                entLitigation.AddEmployeeId = entOldLitigation.AddEmployeeId;
                entLitigation.AddEmployee = entOldLitigation.AddEmployee;
                entLitigation.AddDepartId = entOldLitigation.AddDepartId;
                entLitigation.AddDepart = entOldLitigation.AddDepart;
                entLitigation.Status = 20;
                entLitigation.ApproveEmployeeId = entOldLitigation.ApproveEmployeeId;
                entLitigation.ApproveEmployee = entOldLitigation.ApproveEmployee;
                entLitigation.ApproveReason = entOldLitigation.ApproveReason;
                entLitigation.ApproveOprEmpId = entOldLitigation.ApproveOprEmpId;
                entLitigation.ApproveOprEmp = entOldLitigation.ApproveOprEmp;
                entLitigation.ApproveOprTime = entOldLitigation.ApproveOprTime;
                entLitigation.Suggestion = entOldLitigation.Suggestion;
            }
            else if (status.Equals("诉讼裁决"))
            {
                entLitigation.RecordId = entOldLitigation.RecordId;
                entLitigation.ContractId = entOldLitigation.ContractId;
                entLitigation.ContractCode = entOldLitigation.ContractCode;
                entLitigation.HouseAddress = entOldLitigation.HouseAddress;
                entLitigation.AppCityId = entOldLitigation.AppCityId;
                entLitigation.AppCity = entOldLitigation.AppCity;
                entLitigation.AppCompanyId = entOldLitigation.AppCompanyId;
                entLitigation.AppCompany = entOldLitigation.AppCompany;
                entLitigation.AppDepartId = entOldLitigation.AppDepartId;
                entLitigation.AppDepart = entOldLitigation.AppDepart;
                entLitigation.AppDate = entOldLitigation.AppDate;
                entLitigation.LitigationMoney = entOldLitigation.LitigationMoney;
                entLitigation.LitigationPerson = entOldLitigation.LitigationPerson;
                entLitigation.AddTime = entOldLitigation.AddTime;
                entLitigation.AddEmployeeId = entOldLitigation.AddEmployeeId;
                entLitigation.AddEmployee = entOldLitigation.AddEmployee;
                entLitigation.AddDepartId = entOldLitigation.AddDepartId;
                entLitigation.AddDepart = entOldLitigation.AddDepart;
                entLitigation.Status = 30;
                entLitigation.ApproveEmployeeId = entOldLitigation.ApproveEmployeeId;
                entLitigation.ApproveEmployee = entOldLitigation.ApproveEmployee;
                entLitigation.ApproveReason = entOldLitigation.ApproveReason;
                entLitigation.ApproveOprEmpId = entOldLitigation.ApproveOprEmpId;
                entLitigation.ApproveOprEmp = entOldLitigation.ApproveOprEmp;
                entLitigation.ApproveOprTime = entOldLitigation.ApproveOprTime;
                entLitigation.CurrentTrialStatus = entOldLitigation.CurrentTrialStatus;
                entLitigation.Suggestion = entOldLitigation.Suggestion;
            }
            else if (status.Equals("诉讼结案"))
            {
                entLitigation.RecordId = entOldLitigation.RecordId;
                entLitigation.ContractId = entOldLitigation.ContractId;
                entLitigation.ContractCode = entOldLitigation.ContractCode;
                entLitigation.HouseAddress = entOldLitigation.HouseAddress;
                entLitigation.AppCityId = entOldLitigation.AppCityId;
                entLitigation.AppCity = entOldLitigation.AppCity;
                entLitigation.AppCompanyId = entOldLitigation.AppCompanyId;
                entLitigation.AppCompany = entOldLitigation.AppCompany;
                entLitigation.AppDepartId = entOldLitigation.AppDepartId;
                entLitigation.AppDepart = entOldLitigation.AppDepart;
                entLitigation.AppDate = entOldLitigation.AppDate;
                entLitigation.LitigationMoney = entOldLitigation.LitigationMoney;
                entLitigation.LitigationPerson = entOldLitigation.LitigationPerson;
                entLitigation.AddTime = entOldLitigation.AddTime;
                entLitigation.AddEmployeeId = entOldLitigation.AddEmployeeId;
                entLitigation.AddEmployee = entOldLitigation.AddEmployee;
                entLitigation.AddDepartId = entOldLitigation.AddDepartId;
                entLitigation.AddDepart = entOldLitigation.AddDepart;
                entLitigation.Status = 40;
                entLitigation.ApproveEmployeeId = entOldLitigation.ApproveEmployeeId;
                entLitigation.ApproveEmployee = entOldLitigation.ApproveEmployee;
                entLitigation.ApproveReason = entOldLitigation.ApproveReason;
                entLitigation.ApproveOprEmpId = entOldLitigation.ApproveOprEmpId;
                entLitigation.ApproveOprEmp = entOldLitigation.ApproveOprEmp;
                entLitigation.ApproveOprTime = entOldLitigation.ApproveOprTime;
                entLitigation.RulingMode = entOldLitigation.RulingMode;
                entLitigation.CurrentTrialStatus = entOldLitigation.CurrentTrialStatus;
            }
            return entLitigation;
        }
        catch (Exception ex)
        {
            return null;
        }
    }

    //*******************************************
    //功能概要       ：填充诉讼信息字段
    //参数説明       ：context 请求上下文
    //返回值説明     ：诉讼信息实体
    //功能詳細       ：填充诉讼信息字段
    //作成者         ：zou.xiaochun
    //作成日         ：2010-09-28
    //*******************************************
    private Chenxin.Lib.Business.Entity.t_Business_LitigationSubInfo CompleteLitigationSub(int CurrentTrialStatus, Chenxin.Lib.Business.Entity.t_Business_LitigationSubInfo entLitigationSub,Chenxin.Lib.Business.Entity.t_Business_LitigationSubInfo entOldLitigationSub)
    {
        if (CurrentTrialStatus == 10)
        {
            entLitigationSub.RecordId = entOldLitigationSub.RecordId;
            entLitigationSub.MainId = entOldLitigationSub.MainId;
            entLitigationSub.SecTrialDate = entOldLitigationSub.SecTrialDate;
            entLitigationSub.SecTrialCourt = entOldLitigationSub.SecTrialCourt;
            entLitigationSub.SecTrialJudge = entOldLitigationSub.SecTrialJudge;
            entLitigationSub.SecTrialMemo = entOldLitigationSub.SecTrialMemo;
            entLitigationSub.LastTrialDate = entOldLitigationSub.LastTrialDate;
            entLitigationSub.LastTrialCourt = entOldLitigationSub.LastTrialCourt;
            entLitigationSub.LastTrialJudge = entOldLitigationSub.LastTrialJudge;
            entLitigationSub.LastTrialMemo = entOldLitigationSub.LastTrialMemo;
        }
        else if (CurrentTrialStatus == 20)
        {
            entLitigationSub.RecordId = entOldLitigationSub.RecordId;
            entLitigationSub.MainId = entOldLitigationSub.MainId;
            entLitigationSub.FirstTrialDate = entOldLitigationSub.FirstTrialDate;
            entLitigationSub.FirstTrialCourt = entOldLitigationSub.FirstTrialCourt;
            entLitigationSub.FirstTrialJudge = entOldLitigationSub.FirstTrialJudge;
            entLitigationSub.FirstTrialMemo = entOldLitigationSub.FirstTrialMemo;
            entLitigationSub.LastTrialDate = entOldLitigationSub.LastTrialDate;
            entLitigationSub.LastTrialCourt = entOldLitigationSub.LastTrialCourt;
            entLitigationSub.LastTrialJudge = entOldLitigationSub.LastTrialJudge;
            entLitigationSub.LastTrialMemo = entOldLitigationSub.LastTrialMemo;
        }
        else if (CurrentTrialStatus == 30)
        {
            entLitigationSub.RecordId = entOldLitigationSub.RecordId;
            entLitigationSub.MainId = entOldLitigationSub.MainId;
            entLitigationSub.FirstTrialDate = entOldLitigationSub.FirstTrialDate;
            entLitigationSub.FirstTrialCourt = entOldLitigationSub.FirstTrialCourt;
            entLitigationSub.FirstTrialJudge = entOldLitigationSub.FirstTrialJudge;
            entLitigationSub.FirstTrialMemo = entOldLitigationSub.FirstTrialMemo;
            entLitigationSub.SecTrialDate = entOldLitigationSub.SecTrialDate;
            entLitigationSub.SecTrialCourt = entOldLitigationSub.SecTrialCourt;
            entLitigationSub.SecTrialJudge = entOldLitigationSub.SecTrialJudge;
            entLitigationSub.SecTrialMemo = entOldLitigationSub.SecTrialMemo;
        }
        return entLitigationSub;
    }

    /// <summary>
    /// 保存文件
    /// </summary>
    /// <param name="context">请求上下文</param>
    public void Upload(HttpContext context, string strFile, string recordId)
    {
        try
        {
            Random rd = new Random();
            HttpPostedFile file = context.Request.Files["FileData"];

            string savePath = context.Server.MapPath(Constants.DIRECTORY + strFile);
            string fileName = file.FileName.ToString();
            string saveName = DateTime.Now.ToString("yyyyMMddhhmmss") + rd.Next(100, 999).ToString() + fileName.Substring(fileName.LastIndexOf('.'));

            if (file != null)
            {
                if (!System.IO.Directory.Exists(savePath))
                {
                    System.IO.Directory.CreateDirectory(savePath);
                }
                file.SaveAs(savePath + saveName);
                
                ContractAttachment bllContract = new ContractAttachment();

                Chenxin.Lib.Business.Entity.ContractAttachment entAtt = new Chenxin.Lib.Business.Entity.ContractAttachment();

                entAtt.RecordId = Guid.NewGuid();
                entAtt.RelationId = new Guid(recordId);
                entAtt.FileName = fileName;
                entAtt.Remark = "上传诉讼相关附件";
                entAtt.AttType = 20;
                entAtt.AddTime = DateTime.Now;
                entAtt.CityId = CurrentUserInfo.CityId;
                entAtt.CityName = CurrentUserInfo.CityName;
                entAtt.CompanyId = CurrentUserInfo.CompanyId;
                entAtt.CompanyName = CurrentUserInfo.CompanyName;
                entAtt.DepartId = CurrentUserInfo.DepartId;
                entAtt.DepartName = CurrentUserInfo.DepartName;
                entAtt.UserId = CurrentUserInfo.UserId;
                entAtt.UserName = CurrentUserInfo.UserName;

                if (!string.IsNullOrEmpty(savePath))
                {
                    entAtt.Path = strFile + saveName;
                }

                bllContract.Add(entAtt);
            }
        }
        catch (Exception ex)
        {
            context.Response.Write(retExecResult(Constants.ExecResult.Error, ex.Message, ""));
        }
    }
}